#include "StdAfx.h"
#include "MsgBoxStatu.h"
#include <Pwinuser.h>
#include "CPhoneBookStatu.h"
#include "StaticImg.h"


void CALLBACK OnBackMsgBox(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
{

		KillTimer(GRAPHICMGR.GetWnd(),MSGBOX_BACK);
		CMsgBoxStatu *p= (CMsgBoxStatu*)GRAPHICMGR.GetStatu(L"sub_info");
		if (p)
			p->backClicked();

}
CMsgBoxStatu::CMsgBoxStatu(WCHAR * name):IStatu(name)
{
	m_msgMode=0;
}

bool CMsgBoxStatu::EvaluateClickEvent(const WCHAR* elementName)
{
	if (wcscmp(elementName,L"btn_ok") == 0)
		return backClicked();
	else if (wcscmp(elementName,L"btn_no") == 0)
		return backClicked();
	else if (wcscmp(elementName,L"btn_yes") == 0)
		return OkClicked();
	return false;
}

bool CMsgBoxStatu::EnterStatu()
{
	StaticImg *p1=(StaticImg *)GRAPHICMGR.GetElement(L"sms_Succes");
	p1->setvisible(false);
	StaticImg *p2=(StaticImg *)GRAPHICMGR.GetElement(L"sms_Fail");
	p2->setvisible(false);
	CStaticText *pText=(CStaticText *)GRAPHICMGR.GetElement(L"txtmsg");
	CButton  *pYes,*pNO,*pOk;
	pYes=(CButton *)GRAPHICMGR.GetElement(L"btn_yes");
	pNO=(CButton *)GRAPHICMGR.GetElement(L"btn_no");
	pOk=(CButton *)GRAPHICMGR.GetElement(L"btn_ok");

	KillTimer(GRAPHICMGR.GetWnd(),MSGBOX_BACK);
	SetTimer(GRAPHICMGR.GetWnd(),MSGBOX_BACK,5000,OnBackMsgBox);

	switch(m_msgMode)
	{
	case MSGTEXT:
#ifdef SW_HD

    pText->MoveTo(200, 161);
#else
		pText->MoveTo(125, 92);
#endif

		pOk->setvisible(true);
		pYes->setvisible(false);
		pNO->setvisible(false);
		break;
	case MSGSMSSENDSUCESS:
		{
			p1->setvisible(true);
			pOk->setvisible(true);
			pYes->setvisible(false);
			pNO->setvisible(false);
#ifdef SW_HD
          pText->MoveTo(200, 268);
#else
			pText->MoveTo(125, 157);
#endif

			CSMSAni*pSMSAni=(CSMSAni*)GRAPHICMGR.GetElement(L"SMS_Ani");
			pSMSAni->setvisible(false);

		}
		break;
	case MSGSMSSENDFAILED:
		{
			p2->setvisible(true);
			pOk->setvisible(true);
			pYes->setvisible(false);
			pNO->setvisible(false);
#ifdef SW_HD
         pText->MoveTo(200, 268);
#else
			pText->MoveTo(125, 157);
#endif
			CSMSAni*pSMSAni=(CSMSAni*)GRAPHICMGR.GetElement(L"SMS_Ani");
			pSMSAni->setvisible(false);
		}
		break;
	case MSGSAVEPHONENOTE:
		{
#ifdef SW_HD
           pText->MoveTo(200, 161);
#else
			pText->MoveTo(120, 107);
#endif

			pOk->setvisible(false);
			pYes->setvisible(true);
			pNO->setvisible(true);

		}

		break; 

	}
	if (!g_bForeground)
	{
		::SetForegroundWindow(GRAPHICMGR.GetWnd());
		::MoveWindow(GRAPHICMGR.GetWnd(),0,0,SCREEN_WIDTH,SCREEN_HEIGHT,false);
		::ShowWindow(GRAPHICMGR.GetWnd(),SW_SHOW);
	}

	return true;
}
bool CMsgBoxStatu::backClicked()
{
	/*if (!g_bForeground)
	{
		::MoveWindow(GRAPHICMGR.GetWnd(),0,0,0,0,false);
		ShowWindow(GRAPHICMGR.GetWnd(),SW_HIDE);
	}*/
	if (!g_bForeground)
	{
		::MoveWindow(GRAPHICMGR.GetWnd(),0,0,0,0,false);
		ShowWindow(GRAPHICMGR.GetWnd(),SW_HIDE);

	}
	GRAPHICMGR.BackState(false);
	return true;
}

bool CMsgBoxStatu::OkClicked()
{   
	switch(m_msgMode)
	{
	case MSGSAVEPHONENOTE:
      //  GRAPHICMGR.PostChange(L"NaviPathSTATE");
		{
			CPhoneBookStatu *p=(CPhoneBookStatu *)GRAPHICMGR.GetStatu(L"PhoneBookDetail");
			p->SavePhoneNote();
			GRAPHICMGR.BackState(false);
		}
		break;
	case MSGCALIBRATE:
		//TouchCalibrate();
		GRAPHICMGR.BackState(false);
		m_msgMode=0;
		break; 
	case MSGRESTORE:
		break;
	default :
		break;
	}
	/*TCHAR szLastState[256]={0};
	GRAPHICMGR.GetAndDeleteLatestStatu(szLastState);
	wstring strLastState=szLastState;*/



	return true;
}